package com.xwh.week4;

public class Practice6 {
    public static void main(String[] args) {
        int ans=0;
       for(int i=1;i<1000000;i++){
           if(method(i)){
               ans+=i;
           }
       }
        System.out.println(ans);
    }
    public static boolean method(int n){
        String s1 = Integer.toString(n, 2);
        String s2=Integer.toString(n);
        return method3(s1)&&method3(s2);
    }
    public static boolean method3(String s){
        char[] chars = s.toCharArray();
        if (chars[0] == '0') {
            return false;
        }
        boolean flag=true;
        int left=0;
        int right=s.length()-1;
        while (left<=right){
            if(chars[left]==chars[right]){
                left++;
                right--;
            }else {
                flag=false;
                return flag;
            }
        }
        return flag;
    }
}
